import { Injectable } from '@angular/core';

import sweetAlert2, { SweetAlertOptions } from 'sweetalert2';

@Injectable({
	providedIn: 'root',
})
export class SweetAlertService {
	defaultOption: SweetAlertOptions = { type: 'warning', confirmButtonText: '确定', cancelButtonText: '取消' };
	constructor() {}
	alert(text: string, opt?: SweetAlertOptions) {
		return sweetAlert2.fire({ text, ...this.defaultOption, ...opt });
	}
	confirm(text: string, opt?: SweetAlertOptions) {
		return sweetAlert2.fire({ text, ...this.defaultOption, showCancelButton: true, ...opt });
	}
	prompt(text: string, opt?: SweetAlertOptions) {
		return sweetAlert2.fire({ text, ...this.defaultOption, showCancelButton: true, input: 'text', ...opt });
	}
}
